<?php

/**
 * Manage Comment
 */
class CommentController extends Controller {

    /**
     * show all comment of post
     * @param int $id id of post
     */
    public function actionIndex($post, $title) {
	$model = new Comment('search');
	$model->unsetAttributes();  // clear any default values

	if (isset($_GET['Comment'])) {
	    $model->attributes = $_GET['Comment'];
	}
	$title = urldecode($title);
	$this->render('index', array(
	    'model' => $model,
	    'post' => $post,
	    'title' => $title
	));
    }

    /**
     * @param int $id id of comment     
     */
    public function actionDelete($id) {
	$model = $this->_loadModel($id);
	$model->delete();
    }

    private function _loadModel($id) {
	$model = Comment::model()->findByPk($id);
	if ($model) {
	    return $model;
	} else {
	    throw new CHttpException(404, 'Page was not existed');
	}
    }

}

